package com.byd.modules.biz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.byd.common.utils.PageUtils;
import com.byd.common.utils.Query;
import com.byd.common.utils.R;
import com.byd.modules.biz.entity.DimensionEntity;
import com.byd.modules.biz.entity.EmotionEntity;
import com.byd.modules.biz.service.EmotionService;




/**
 * 情感词库
 * 
 * @author YMX
 * @email YMX@gmail.com
 * @date 2017-12-27 20:02:39
 */
@RestController
@RequestMapping("/emotion")
public class EmotionController {
	@Autowired
	private EmotionService emotionService;
	
	@RequestMapping("/list")
	public List list(@RequestParam Map<String, Object> params){
		//查询列表数据

		List<EmotionEntity> emotionList = emotionService.queryList(params);
		
		return emotionList;
	}

	@RequestMapping("/list2/{emotionWord}")
	public List list2(@PathVariable("emotionWord") String emotionWord){
		//查询列表数据
		Map<String, Object> query = new HashMap<>();
    	if (!emotionWord.equals("null")) {
    		query.put("emotionWord", emotionWord);
		}
		List<EmotionEntity> emotionList = emotionService.queryList(query);
		
		return emotionList;
	}

	@RequestMapping("/level1list/{emotionWord}")
	public List level1list(@PathVariable("emotionWord") String emotionWord){
		//查询列表数据
		Map<String, Object> query = new HashMap<>();
    	if (!emotionWord.equals("null")) {
    		query.put("emotionWord", emotionWord);
		}
    	query.put("level", "1");
		List<EmotionEntity> emotionList = emotionService.queryList(query);
		
		return emotionList;
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("emotion:info")
	public R info(@PathVariable("id") Long id){
		EmotionEntity emotion = emotionService.queryObject(id);
		
		return R.ok().put("emotion", emotion);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("emotion:save")
	public R save(@RequestBody EmotionEntity emotion){
		emotionService.save(emotion);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("emotion:update")
	public R update(@RequestBody EmotionEntity emotion){
		emotionService.update(emotion);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("emotion:delete")
	public R delete(@RequestBody Long id){
		emotionService.delete(id);
		
		return R.ok();
	}
	
	@RequestMapping("/export")
    public void exportFeaturesByParam(@RequestParam Map<String, Object> params,HttpServletResponse response) {
        emotionService.export(params, response);
    }

    /**
     * 列表
     */
    @RequestMapping("/listfilter/{parentId}")
    public List<EmotionEntity> listFilter(@PathVariable("parentId") Long parentId) {
        List<EmotionEntity> list = emotionService.queryListFilter(parentId);
        return list;
    }
    @RequestMapping("/listfilterbyname")
    public List<EmotionEntity> listFilterByName(String name) {
        List<EmotionEntity> list = emotionService.queryListFilterByName(name);
        return list;
    }
}
